package com.andeveloper.springdemo.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class WelcomeAdvice {
	
	
	private static Logger logger = Logger.getLogger(WelcomeAdvice.class);
	
	@Pointcut("execution(* com.andeveloper.springdemo.service.welcome.WelcomeService.* (..))")
	public void welcome() {
		
	}
	@Before("welcome()")
	public void beforeWelcome() {
		logger.info("beforeWelcome");
	}
	@After("welcome()")
	public void afterWelcome() {
		logger.info("afterWelcome");
	}

	@Around("welcome()")
	public Object welcoming(ProceedingJoinPoint joinPoint) {
		Object result = null;
		long startTime = System.currentTimeMillis();
		try {
			result = joinPoint.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		long endTime = System.currentTimeMillis();
		logger.info("welcoming time:"+ (endTime - startTime)+ "ms");
		return result;
	}
}
